import {createRouter, createWebHistory} from 'vue-router'
import routes from './router'
import cookieUtil from '../utils/cookiesUtil'

const router = createRouter({
    history: createWebHistory(),  
    routes: routes,
})

router.beforeEach((to, from, next) => {
    if(to.matched.some(res => res.meta. authRequied)){
        var token = cookieUtil.getCookie("token")
        // console.log(token);
        if(token!=""){
            next()
        }
        else{
            next({
                path:'/'
            })
        }
    }
    else{
        next()
    }
    
})

export default router